package com.deryun.tyl.bean.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.deryun.tyl.bean.Policy;
import com.deryun.tyl.bean.Publicity;

public interface PublicityMapper {
	
	@Insert({
		"INSERT INTO publicity (title,publishDate,context,publishMan,publishUserId,level,result) VALUES ("
		+ "#{title,jdbcType=VARCHAR},"
		+ "#{publishDate,jdbcType=VARCHAR},"
		+ "#{context,jdbcType=VARCHAR},"
		+ "#{publishMan,jdbcType=VARCHAR},"
		+ "#{publishUserId,jdbcType=VARCHAR},"
		+ "#{level,jdbcType=VARCHAR}"
		+ "#{result,jdbcType=VARCHAR}"
		+ ")"
	})
	int addPublicity(Publicity publicity);
	
	//普通用户使用
	@Select({
		"SELECT * FROM publicity ORDER BY id DESC"
	})
	@ResultMap("BaseResultMap")
	List<Publicity> getAllPublicity();
	
	//管理员用户使用
	@Select({
		"SELECT * FROM publicity WHERE publishUserId = #{0,jdbcType=VARCHAR} ORDER BY id DESC"
	})
	@ResultMap("BaseResultMap")
	List<Publicity> getUserPublicity(String publishUserId);
	
	@Delete({
		"DELETE FROM publicity WHERE id=#{0,jdbcType=INTEGER}"
	})
	int deletePublicity(int id);
	
	//修改政策法规
	@Update({
		"UPDATE publicity p SET "
		+ "p.context = #{context,jdbcType=VARCHAR} AND "
		+ "p.title = #{title,jdbcType=VARCHAR} AND "
		+ "p.`level` = #{level,jdbcType=VARCHAR} AND "
		+ "p.result = 0 "
		+ "WHERE "
		+ "p.id = #{id,jdbcType=INTEGER}"
	})
	int modifyPublicity(Publicity publicity);
	
	//查看详细政策法规
	@Select({
		"SELECT * FROM publicity WHERE id = #{0,jdbcType=INTEGER} ORDER BY id DESC"
	})
	@ResultMap("BaseResultMap")
	Publicity getPublicityById(int id);
	
	//审批
	@Update({
		"UPDATE publicity p SET "
		+ "p.result = #{result,jdbcType=INTEGER} "
		+ "WHERE "
		+ "p.id = #{id,jdbcType=INTEGER}"
	})
	int setResult(Publicity publicity);
}
